package com.ssh.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.ssh.entity.User;
import com.ssh.service.UserService;

public class UserJsonAction extends ActionSupport implements ModelDriven<User>{
	//模型驱动用到的对象
	private User user = new User();
	
	public User getModel() {
		return user;
	}
	
	//注入service
	private UserService userService;
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	//创建一个json返回结果
	private Map<String, Object> jsonResult;
	public Map<String, Object> getJsonResult() {
		return jsonResult;
	}
	public void setJsonResult(Map<String, Object> jsonResult) {
		this.jsonResult = jsonResult;
	}


	public String getAllUserJson(){
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<User> list = userService.getAllUser();
		if(list.size() < 0) {
			modelMap.put("success", false);
			modelMap.put("msg", "error");
			jsonResult = modelMap;
			return "error";
		}else {
			modelMap.put("success",true);
			modelMap.put("userList", list);
			jsonResult = modelMap;
			return "getAllUserJson";
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
